﻿<%@ Page Language="vb" AutoEventWireup="false" Codebehind="SelectUser3.aspx.vb" Inherits="PubProject.SelectUser3" %>
<%@ Register TagPrefix="mnu" Namespace="Mysoft.Map.Application.Menus" Assembly="Mysoft.Map.Application.Components" %>
<%@ Register TagPrefix="cnt" Namespace="Mysoft.Map.Application.Controls" Assembly="Mysoft.Map.Application.Components" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
	<HEAD>
		<title></title>
		<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
		<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
		<meta content="JavaScript" name="vs_defaultClientScript">
		<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
		<script language="javascript" src="/_controls/settings.aspx"></script>
		<LINK href="/_common/styles/global.css" type="text/css" rel="stylesheet">
		<LINK href="/_common/styles/dialogs.css" type="text/css" rel="stylesheet">
		<LINK href="/_nav/taskbox.css" type="text/css" rel="stylesheet">
		<LINK href="/_controls/tree/tree.css" type="text/css" rel="stylesheet">
		<script language="javascript" src="/_common/scripts/global.js"></script>
		<script language="javascript" src="/_controls/util/util.js"></script>
		<script language="javascript" src="/_forms/FormBase.js"></script>
		<script language="javascript" src="/_controls/lookup/map_LookupDialogs.js"></script>
		<!-- Find --><LINK href="/_controls/find/find.css" type="text/css" rel="stylesheet">
		<script language="javascript" src="/_controls/find/find.js"></script>
		<!-- Menu --><LINK href="/_nav/menu.css" type="text/css" rel="stylesheet">
		<script language="javascript" src="/_nav/menu.js"></script>
		<!-- Grid --><LINK href="/_grid/map_grid.css" type="text/css" rel="stylesheet">
		<script language="javascript">
		
			function window.onload()
			{
				__appFind_switch_standard.style.display = "none";
				__appFind_switch_advanced.style.display = "none";
				 
				if(mapForm.txtCurBUCode.value != "")
				{
					Table1.focusNodeByCode(mapForm.txtCurBUCode.value);
				}
				 
			}
			
			//点击树导航记录时，刷新
			function TrClick(obj)
			{
				Table1.clickNode(obj);
				
				appFind.clearQuery();
				
				appGridQuery();
				
			}
			
			//待选择用户列表刷新数据
			function appGridQuery()
			{
				var s = appFind.queryxml;
				var sFilt = "";

 
				if (s == '<filter type=\"and\"/>')
				{	
				 
					var obj = Table1.lastObj;
					var sCode = obj.code;
					var sGuid = obj.value;
					var sButype = obj.butype;
					var bOnlyLocal = true;

					//显示范围
					if (document.all("chkAll").checked == true) bOnlyLocal = false;
					
					//选中部门
					if (sButype == "1")
					{
				 
						sFilt = "a.HierarchyCode ='" + sCode + "'"
						if (bOnlyLocal == false) sFilt += " OR a.HierarchyCode like '" + sCode + ".%'";
					}
					else
					{
					 
						if (bOnlyLocal == true)
						{
					 
							//只显示本级单级岗位下的用户
							//sFilt = "b.BUGUID ='" + sGuid + "'";
							sFilt = "a.HierarchyCode ='" + sCode + "'";
						}
						else
						{
						 
							//与部门的一样
							sFilt = "a.HierarchyCode ='" + sCode + "' OR a.HierarchyCode like '" + sCode + ".%'";
						 }
					}
				}
				else
				{
				 
					//加传入的公司（单位）过滤，如传入的公司（单位）为空则不加任何过滤
					var sCode = mapForm.txtCurBUCode.value;
					if (sCode != "") sFilt = "a.HierarchyCode ='" + sCode + "' OR a.HierarchyCode like '" + sCode + ".%'";
				}
				
				appGrid.frameElement.filter = s;
				appGrid.frameElement.customFilter = sFilt;
				var sAppliedBy = __SelectedUser.value;
				//alert(sAppliedBy)
				appGrid.frameElement.Query(sAppliedBy);
			}
			
			//已选择用户刷新数据
			function appGrid2Query()
			{
				var sText = document.all.txtUserGUIDList.value;
				var sFilt = "";
				if (sText != "")  
				{
					sFilt = "convert(varchar(40),UserGUID) in ('" + sText.replace(/,/g,"','") + "')"
				}
				else
				{
					sFilt = "1=2"
				}
				appGrid2.frameElement.customFilter = sFilt;
				appGrid2.frameElement.Query(); 
			}
			
			//查询
			function myQuery()
			{
				appGridQuery();
			}
			
			//双击待选用户列表
			function appGridDbClick()
			{
				if (document.all.txtMultiSelect.value == "1")
				{
					btnAddClick();	//多选时为添加功能
				}	
				else
				{
					btnOk.click();	//确定功能
				}
			}
			
			//添加用户
			function btnAddClick()
			{
				var arrTr = appGrid.frameElement.getSelected();
				if (!arrTr) return;

				var sTmp = document.all.txtUserGUIDList.value;
				var sTmp2 = "," + sTmp.toUpperCase() + ",";
				var iCount = 0;
				for (var i=0;i<arrTr.length;i++)
				{
					if (sTmp == "") 
					{	
						sTmp = arrTr[i].UserGUID;
						iCount ++;
					}
					else
					{
						//检查是否已选择过
						if (sTmp2.indexOf("," + arrTr[i].UserGUID.toUpperCase() + ",") == -1)
						{
							sTmp += "," + arrTr[i].UserGUID.toUpperCase() ;
							iCount ++;
						}
					}
				}
				
				if (iCount >0 ) 
				{
					document.all.txtUserGUIDList.value = sTmp;
					appGrid2Query();
				}
			}
			
			//删除已选客户
			function btnReMoveClick()
			{
				var arrTr = appGrid2.frameElement.getSelected();
				if (!arrTr) return;
				
				var sTmp = document.all.txtUserGUIDList.value;
				var sTmp = "," + sTmp.toUpperCase() + ",";
				
				for (var i=0;i<arrTr.length;i++)
				{
					sTmp = sTmp.replace(","+arrTr[i].UserGUID.toUpperCase()+",","," );
				}
				
				sTmp = sTmp.substr(1,sTmp.length-1);
				document.all.txtUserGUIDList.value = sTmp;
				appGrid2Query();
			}
			
			//清空
			function btnClearClick()
			{
				var ls = new LookupItems();
				var li = new LookupItem();

				li.id		= "";
				li.name		= "";
				li.html		= "";
				
				//给values赋值
				var arrValues = new Array();
				
				for (var i=0; i < 8; i++)
				{
					//定义values格式： name、value
					var lItemData = new LookupItemData();
					
					lItemData.name="";
					lItemData.value="";
					
					//保存在行数组里
					arrValues.push(lItemData);
				}
				
				li.values	= arrValues;
				li.keyValues	= null;
				ls.items.push(li);
				
				parent.window.returnValue=ls;
				parent.window.close();
				
			}
					//返回值：lookup返回值格式如下：
			//     id				用户GUID
			//     name            用户名称
			//     html　　　　　　“<img class='lui' src='/_imgs/ico_16_10003.gif'> "＋用户名称
			//     values    (数组)
			//          [0]  用户代码
			//               name  (列名)
			//               value  (列值)
			//          [1]  上级部门代码
			//               name  (列名)
			//               value  (列值)
			//          [2]  上级部门名称
			//               name  (列名)
			//               value  (列值)
			//          [3]  上级部门是否公司（1－是；0－否）
			//               name  (列名)
			//               value  (列值)
			//          [4]  办公电话
			//               name  (列名)
			//               value  (列值)
			//          [5]  手机
			//               name  (列名)
			//               value  (列值)
			//          [6]  Email
			//               name  (列名)
			//               value  (列值)

			//访问返回值举例
			//访问返回的行数：arrReturn.items.length
			//访问id:         arrReturn.items[0].id
			//访问name:       arrReturn.items[0].name   
			//访问html:       arrReturn.items[0].html   
			//访问第一行第一列的值对应字段:       arrReturn.items[0].values[0].name
			//访问第一行第一列的值:       arrReturn.items[0].values[0].value

			function okClick()
			{
				var arrTr;
				
				//多选
				if (document.all.txtMultiSelect.value == "1")
				{
					arrTr = appGrid2.frameElement.getAllRows();
				}
				else
				{
					arrTr = appGrid.frameElement.getSelected();
				}
				
				if (!arrTr) return;
				
				var ls = new LookupItems();
				for (var i=0;i< arrTr.length;i++)
				{
					var li = new LookupItem();

					li.id		= arrTr[i].UserGUID;
					li.name		= arrTr[i].UserName;
					li.html		= "<img class='lui' src='/_imgs/ico_16_10003.gif'>" + arrTr[i].UserName;
					
					//定义values格式： name、value
					var arrValues = new Array();
					var lItemData = new LookupItemData();
					
					lItemData.name="UserCode";
					lItemData.value=arrTr[i].UserCode;
					arrValues.push(lItemData);
					
					lItemData = new LookupItemData();
					lItemData.name="HierarchyCode";
					lItemData.value=arrTr[i].HierarchyCode;
					arrValues.push(lItemData);
					
					lItemData = new LookupItemData();
					lItemData.name="BUName";
					lItemData.value=arrTr[i].BUName;
					arrValues.push(lItemData);
					
					var sIsCompany;
					sIsCompany=arrTr[i].IsCompany;//数据库返回值为True/False,要将其转化为1/0
					if (sIsCompany.toUpperCase()=="TRUE")
						sIsCompany="1";
					else
						sIsCompany="0";
						
					lItemData = new LookupItemData();
					lItemData.name="IsCompany";
					lItemData.value=sIsCompany;
					arrValues.push(lItemData);
					
					lItemData = new LookupItemData();
					lItemData.name="OfficePhone";
					lItemData.value=arrTr[i].OfficePhone;
					arrValues.push(lItemData);
					
					lItemData = new LookupItemData();
					lItemData.name="MobilePhone";
					lItemData.value=arrTr[i].MobilePhone;
					arrValues.push(lItemData);
					
					lItemData = new LookupItemData();
					lItemData.name="Email";
					lItemData.value=arrTr[i].Email;
					arrValues.push(lItemData);
					
					lItemData = new LookupItemData();
					lItemData.name="BUGUID";
					lItemData.value=arrTr[i].BUGUID;
					arrValues.push(lItemData);
					
					lItemData = new LookupItemData();
					lItemData.name="CompanyGUID";
					lItemData.value=arrTr[i].CompanyGUID;
					arrValues.push(lItemData);
					
					li.values	= arrValues;			
					li.keyValues	= null;
					
					ls.items.push(li);
				}
				
				parent.window.returnValue=ls;
				parent.window.close();
				
			}
			
		</script>
	</HEAD>
	<body MS_POSITIONING="GridLayout">
		<table style="TABLE-LAYOUT: fixed" height="100%" cellSpacing="0" cellPadding="0" width="100%">
			<tr>
				<td class="main">
					<table style="TABLE-LAYOUT: fixed" height="100%" cellSpacing="0" cellPadding="0" width="100%">
						<colgroup>
							<col width="255">
							<col width="10">
							<col>
						</colgroup>
						<TBODY>
							<tr height="20">
								<td><b style="COLOR: #666666">请选择单位:</b></td>
								<td></td>
								<td></td>
							</tr>
							<tr>
								<td class="wizBox1">
									<DIV style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; OVERFLOW: auto; WIDTH: 100%; PADDING-TOP: 5px; HEIGHT: 100%">
										<form id="mapForm" method="post" runat="server">
											<asp:textbox id="txtUserFullCodeList" style="DISPLAY: none" Runat="server"></asp:textbox>
											<asp:textbox id="txtUserGUIDList" style="DISPLAY: none" Runat="server"></asp:textbox>
											<asp:textbox id="txtCurBUCode" style="DISPLAY: none" Runat="server"></asp:textbox>
											<asp:textbox id="txtMultiSelect" style="DISPLAY: none" Runat="server"></asp:textbox>
											<cnt:repeater id="repBU" runat="server" EnablePager="false" FooterCssClass="footer" LinkCssClass="a1"
												LinkAlign="right" PKField="BldCode" SortSignASC='<img src="/_imgs/ico_arrow_u.gif">' SortSignDESC='<img src="/_imgs/ico_arrow_d.gif">'>
												<HeaderTemplate>
													<TABLE id="Table1" cellspacing="0" cellpadding="0" width="100%" class="singleSelectTree">
												</HeaderTemplate>
												<ItemTemplate>
													<tr height='20' code='<%# DataBinder.Eval(Container, "DataItem.Code") %>'
														 value='<%# DataBinder.Eval(Container, "DataItem.GUID") %>'
														 text='<%# DataBinder.Eval(Container, "DataItem.Name") %>'
														 companyguid='<%# DataBinder.Eval(Container, "DataItem.companyguid") %>'
														 butype='<%# DataBinder.Eval(Container, "DataItem.butype") %>'
														 is_hide="false" onclick="TrClick(this)" 
														 onmouseover='this.bgColor="#E3E9F4"' onmouseout='this.bgColor="#ffffff"'>
														<td>
															<span></span><label style="CURSOR: hand"></label><img title="<%# iif(DataBinder.Eval(Container, "DataItem.butype") ="0" ,"公司",iif(DataBinder.Eval(Container, "DataItem.butype") ="1","部门",iif(DataBinder.Eval(Container, "DataItem.butype") ="2","团队","项目团队"))) %>" src='<%# iif(DataBinder.Eval(Container, "DataItem.butype") ="0" ,"/images/Company_16_white.gif",iif(DataBinder.Eval(Container, "DataItem.butype") ="1","/images/Department_16_white.gif",iif(DataBinder.Eval(Container, "DataItem.butype") ="2","/images/Team_16_white.gif","/images/ProjectTeam_16_white.gif"))) %>'><%# DataBinder.Eval(Container, "DataItem.Name") %>
														</td>
													</tr>
												</ItemTemplate>
												<FooterTemplate>
					</table>
					</FooterTemplate> </cnt:repeater></FORM></DIV></td>
				<td></td>
				<td>
					<table class="appQuery" id="appQuery" style="TABLE-LAYOUT: fixed; FONT-SIZE: 9pt" height="100%"
						cellSpacing="0" cellPadding="0" width="100%" border="0" onquery="myQuery()">
						<colgroup>
							<col width="100%">
						</colgroup>
						<tr height="63">
							<td><cnt:appfind id="appFind" runat="server"></cnt:appfind></td>
						</tr>
						<tr height="1">
							<td></td>
						</tr>
						<tr height="23">
							<td><mnu:appgridmenu id="appGridMenu" runat="server"></mnu:appgridmenu></td>
						</tr>
						<tr>
							<td><cnt:appgrid id="appGrid" runat="server" Filter="<filter />"></cnt:appgrid></td>
						</tr>
						<tr id="Tr1" height="30" runat="server">
							<td align="center"><button id="btnAdd" style="WIDTH: 70px" onclick="btnAddClick()" type="button">添加▼</button>
								<span style="WIDTH: 100px"></span><button id="btnReMove" style="WIDTH: 70px" onclick="btnReMoveClick()" type="button">
									移除▲</button>
							</td>
						</tr>
						<tr id="Tr2" height="20" runat="server">
							<td><mnu:appgridmenu id="appMenu2" runat="server"></mnu:appgridmenu></td>
						</tr>
						<tr id="Tr3" height="35%" runat="server">
							<td><cnt:appgrid id="appGrid2" runat="server" Filter="<filter />" AllowPaging="False"></cnt:appgrid></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		</TD></TR>
		<tr height="40">
			<td class="buttons">
					<button style="WIDTH:70px" onclick="okClick()" id="btnOk" type="button">
					确 定</button>&nbsp;&nbsp; <button style="WIDTH:70px" onclick="parent.window.close();" type="button">
					取 消</button>&nbsp;&nbsp; <button id="btnClear" style="WIDTH: 70px" onclick="btnClearClick()" type="button" runat="server">
					清 空</button>
			</td>
		</tr>
		</TBODY></TABLE>
	</body>
</HTML>

